package com.sky.task;


import com.sky.WeSocket.WebSocketServer;
import com.sky.config.WebSocketConfiguration;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
 * @author: Joey
 * @Description:
 * @date:2024/5/3 23:33
 */
public class WebSocketTask {
    @Autowired
    private WebSocketServer webSocketConfiguration;

    /**
     * 通过WebSocket每隔5秒向客户端发送消息
     */
    //@Scheduled(cron = "0/5 * * * * ?")
    public void sendMessageToClient() {
        webSocketConfiguration.sendToAllClient("这是来自服务端的消息：" + DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalDateTime.now()));
    }
}
